package demo7;

class Shapes {

    public void draw() {
        System.out.println("画图");
    }
}

class Cycle extends Shapes{
    @Override
    public void draw() {
        System.out.println("●");
    }
}

class Rect extends Shapes{
    @Override
    public void draw() {
        System.out.println("◇");
    }
}

class Flower extends Shapes{
    @Override
    public void draw() {
        System.out.println("❀");
    }
}

public class TestDemo {
    // 编译器在编译代码时，并不知道要调用Rect、Cycle、Flower中draw()的方法
    // 等程序运行起来后，引用的具体对象确定后，才知道调用哪个方法
    public static void main(String[] args) {
        Rect rect = new Rect();
        Cycle cycle = new Cycle();
        Flower flower = new Flower();

        Shapes[] shapes = {cycle,rect,flower};
        for (Shapes shape : shapes) {
            shape.draw();
        }
    }
}
